package com.example.common.module

import com.example.common.api.BaseApiServer
import com.example.net.HttpInterceptorType
import com.example.net.HttpManager

abstract class BaseRepository<T:BaseApiServer> {

    private var tokenApiServer:T? = null
    private var signApiServer:T? = null
    private var uploadApiServer:T? = null
    private var commonApiServer:T? = null

    fun<T>createApiServer(clazz:Class<T>,type:HttpInterceptorType):T{
        if(HttpInterceptorType.TOKEN == type){
            if(tokenApiServer == null){
                tokenApiServer = HttpManager.createApiService(clazz,type)
            }
            return tokenApiServer as T
        }
        if(HttpInterceptorType.SIGN == type){
            if(signApiServer == null){
                signApiServer = HttpManager.createApiService(clazz,type)
            }
            return signApiServer as T
        }
        if(HttpInterceptorType.UPLOAD == type){
            if(uploadApiServer == null){
                uploadApiServer = HttpManager.createApiService(clazz,type)
            }
            return uploadApiServer as T
        }

        if(HttpInterceptorType.INTERCEPTOR == type){
            if(commonApiServer == null){
                commonApiServer = HttpManager.createApiService(clazz,type)
            }
            return commonApiServer as T
        }
        return HttpManager.createApiService(clazz,type) as T
    }
}